{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 波士顿房价预测案例——线性回归分析\n",
    "\n",
    "在这个案例中，我们将利用波士顿郊区的房屋信息数据训练和测试一个模型，并对模型的性能和预测能力进行测试。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 读取数据\n",
    "做完特征工程后的数据，请先运行2_FE_BostonHousePrice.ipynb，得到文件FE_boston_housing.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CRIM</th>\n",
       "      <th>ZN</th>\n",
       "      <th>INDUS</th>\n",
       "      <th>CHAS</th>\n",
       "      <th>NOX</th>\n",
       "      <th>RM</th>\n",
       "      <th>AGE</th>\n",
       "      <th>DIS</th>\n",
       "      <th>TAX</th>\n",
       "      <th>PTRATIO</th>\n",
       "      <th>...</th>\n",
       "      <th>RAD_2</th>\n",
       "      <th>RAD_3</th>\n",
       "      <th>RAD_4</th>\n",
       "      <th>RAD_5</th>\n",
       "      <th>RAD_6</th>\n",
       "      <th>RAD_7</th>\n",
       "      <th>RAD_8</th>\n",
       "      <th>RAD_24</th>\n",
       "      <th>MEDV</th>\n",
       "      <th>log_MEDV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.067815</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.314815</td>\n",
       "      <td>0.577505</td>\n",
       "      <td>0.641607</td>\n",
       "      <td>0.269203</td>\n",
       "      <td>0.208015</td>\n",
       "      <td>0.3</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.422222</td>\n",
       "      <td>0.666856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.547998</td>\n",
       "      <td>0.782698</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.5</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.368889</td>\n",
       "      <td>0.619696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.694386</td>\n",
       "      <td>0.599382</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.5</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.660000</td>\n",
       "      <td>0.833335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000293</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.658555</td>\n",
       "      <td>0.441813</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.6</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.631111</td>\n",
       "      <td>0.816001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.000705</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.687105</td>\n",
       "      <td>0.528321</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.6</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.693333</td>\n",
       "      <td>0.852567</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       CRIM    ZN     INDUS  CHAS       NOX        RM       AGE       DIS  \\\n",
       "0  0.000000  0.18  0.067815   0.0  0.314815  0.577505  0.641607  0.269203   \n",
       "1  0.000236  0.00  0.242302   0.0  0.172840  0.547998  0.782698  0.348962   \n",
       "2  0.000236  0.00  0.242302   0.0  0.172840  0.694386  0.599382  0.348962   \n",
       "3  0.000293  0.00  0.063050   0.0  0.150206  0.658555  0.441813  0.448545   \n",
       "4  0.000705  0.00  0.063050   0.0  0.150206  0.687105  0.528321  0.448545   \n",
       "\n",
       "        TAX  PTRATIO  ...  RAD_2  RAD_3  RAD_4  RAD_5  RAD_6  RAD_7  RAD_8  \\\n",
       "0  0.208015      0.3  ...      0      0      0      0      0      0      0   \n",
       "1  0.104962      0.5  ...      1      0      0      0      0      0      0   \n",
       "2  0.104962      0.5  ...      1      0      0      0      0      0      0   \n",
       "3  0.066794      0.6  ...      0      1      0      0      0      0      0   \n",
       "4  0.066794      0.6  ...      0      1      0      0      0      0      0   \n",
       "\n",
       "   RAD_24      MEDV  log_MEDV  \n",
       "0       0  0.422222  0.666856  \n",
       "1       0  0.368889  0.619696  \n",
       "2       0  0.660000  0.833335  \n",
       "3       0  0.631111  0.816001  \n",
       "4       0  0.693333  0.852567  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "#dpath = './data/'\n",
    "df = pd.read_csv(\"MM_boston_housing.csv\")\n",
    "\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = df[\"MEDV\"]\n",
    "\n",
    "X = df.drop([\"MEDV\", \"log_MEDV\"], axis = 1)\n",
    "\n",
    "#特征名称，用于后续显示权重系数对应的特征\n",
    "feat_names = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当数据量比较大时，可用train_test_split从训练集中分出一部分做校验集；\n",
    "样本数目较少时，建议用交叉验证。\n",
    "在线性回归中，留一交叉验证有简便计算方式。\n",
    "\n",
    "下面将训练数据分割成训练集和测试集，只是让大家对模型的训练误差、校验集上的测试误差估计、和测试集上的测试误差做个比较。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(404, 21)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>RM</td>\n",
       "      <td>0.452377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ZN</td>\n",
       "      <td>0.129239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.103221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>B</td>\n",
       "      <td>0.078899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.059660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.037664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.027465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.013818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>AGE</td>\n",
       "      <td>-0.001228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.055736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.081501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.113548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.151553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.187898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.221874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.386249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.476675</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns      coef\n",
       "5        RM  0.452377\n",
       "1        ZN  0.129239\n",
       "20   RAD_24  0.103221\n",
       "10        B  0.078899\n",
       "3      CHAS  0.059660\n",
       "18    RAD_7  0.037664\n",
       "19    RAD_8  0.030071\n",
       "14    RAD_3  0.027465\n",
       "2     INDUS  0.013818\n",
       "6       AGE -0.001228\n",
       "15    RAD_4 -0.008698\n",
       "16    RAD_5 -0.011517\n",
       "13    RAD_2 -0.040970\n",
       "17    RAD_6 -0.055736\n",
       "12    RAD_1 -0.081501\n",
       "8       TAX -0.113548\n",
       "4       NOX -0.151553\n",
       "9   PTRATIO -0.187898\n",
       "0      CRIM -0.221874\n",
       "7       DIS -0.386249\n",
       "11    LSTAT -0.476675"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 1.使用默认配置初始化学习器实例\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 2.用训练数据训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 3. 用训练好的模型对测试集进行预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.6939789810509476\n",
      "The r2 score of LinearRegression on train is 0.7549146436868177\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print('The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr))\n",
    "#训练集\n",
    "print('The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAAFsCAYAAAAOmoq4AAAABHNCSVQICAgIfAhkiAAAAAlwSF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k42tSlKpDGyp78ykNtjrKWB/aqdePaUlqVs8JS5JUgHsYUuSVIB+/cKBPfbYIydOnNifu5QkaUBZtGjRM5k5pqvP69fAnjhxIgsXLuzPXUqSNKBERN138WvNU+KSJBXAwJYkqQAGtiRJBejXa9iSpPZt2LCBFStW8PLL3iV1sBgxYgQTJkygqampV7ZnYEvSALBixQp22WUXJk6cSERvfUmbGiUzWbt2LStWrGDSpEm9sk1PiUvSAPDyyy+z++67G9aDRESw++679+oZEwNbkgYIw3pw6e3jaWBLklQAr2FL0gDU0tL/2xs2bBiHHnooGzduZNKkSXz3u99lt9126/K+zjvvPD760Y9y0EEHbbX8uuuuY+HChVxzzTVd3ibAyJEjWbduXV3rTps2jSuvvJLm5uYtyxYuXMgNN9zA1Vdf3a39N5o9bEkSAK973etYvHgxDz/8MKNHj2bOnDnd2s43v/nNbcJ6IGhubu7zsN60aVOfbdvAliRtY+rUqaxcuXLL/BVXXMGRRx7JYYcdxqWXXgrA+vXrmTFjBocffjiHHHIIc+fOBWq92823of7Od77DAQccwHHHHcc999yzZXvnnHMOt91225b5kSNHArBu3TqmT5/OEUccwaGHHsrtt9++TW2rVq3i2GOPZfLkyRxyyCH8/Oc/r6tN8+fP58QTTwSgpaWFc889l2nTprHffvttFeQ33ngjRx11FJMnT+aDH/zglhC+8MILaW5u5uCDD97yGkDtttuXXXYZ73znO7n11lvrqqU7PCUuSdrKpk2bmDdvHrNnzwbgzjvvZOnSpTzwwANkJieffDILFixgzZo17L333vz4xz8G4LnnnttqO6tWreLSSy9l0aJFjBo1ine9611MmTJlu/seMWIEP/jBD9h111155plnOProozn55JO3GsD1ve99j+OPP57PfOYzbNq0iRdffLFb7fzNb37DXXfdxQsvvMBb3vIWLrzwQpYtW8bcuXO55557aGpq4qKLLuKmm27i7LPP5ktf+hKjR49m06ZNTJ8+nYceeojDDjtsS9133313t+qol4EtSQLgpZdeYvLkyTz55JO87W1v473vfS9QC+w777xzS9iuW7eOpUuXcswxx/Cxj32MT37yk5x44okcc8wxW23v/vvvZ9q0aYwZU/tiqtNOO43f/va3260hM/n0pz/NggUL2GGHHVi5ciWrV69mr7322rLOkUceybnnnsuGDRs45ZRTmDx5crfaO2PGDHbaaSd22mknxo4dy+rVq5k3bx6LFi3iyCOP3PKajB07FoBbbrmFa6+9lo0bN7Jq1SoeffTRLYF92mmndauGrvCUuCQJeO0a9vLly3nllVe2XMPOTC655BIWL17M4sWLWbZsGbNnz+aAAw5g0aJFHHrooVxyySVcdtll22yzo482DR8+nFdffXXL9l955RUAbrrpJtasWcOiRYtYvHgxe+655zafZT722GNZsGAB48eP56yzzuKGG27oVnt32mmnLdPDhg1j48aNZCazZs3a0tbHHnuMlpYWnnjiCa688krmzZvHQw89xIwZM7aqa+edd+5WDV1hD1tdUu/I1d4e4Sqp/4waNYqrr76amTNncuGFF3L88cfzuc99jjPOOIORI0eycuVKmpqa2LhxI6NHj+bMM89k5MiRXHfddVtt5+1vfzsXX3wxa9euZdddd+XWW2/l8MMPB2rXfRctWsT73/9+br/9djZs2ADUTquPHTuWpqYm7rrrLpYv3/abKJcvX8748eM5//zzWb9+PQ8++CBnn312r7R9+vTpzJw5k4985COMHTuWP/7xj7zwwgs8//zz7LzzzowaNYrVq1fzk5/8hGnTpvXKPutlYEvSANToN71Tpkzh8MMP5+abb+ass85iyZIlTJ06FagNELvxxhtZtmwZH//4x9lhhx1oamri61//+lbbGDduHC0tLUydOpVx48ZxxBFHbBnAdf755zNz5kyOOuoopk+fvqWHesYZZ3DSSSfR3NzM5MmTeetb37pNbfPnz+eKK66gqamJkSNHdtjDnjFjxpb7eE+dOpUPfehDnbb7oIMO4otf/CLve9/7ePXVV2lqamLOnDkcffTRTJkyhYMPPpj99tuPd7zjHfW/mL0kMrPfdtbc3JybRw6qTPawpb6xZMkSDjzwwEaXoV7W3nGNiEWZ2dzBUzrkNWxJkgpgYEuSVAADW5IGiP68RKm+19vH00FnKobXzzWYjRgxgrVr1/oVm4PE5u/DHjFiRK9t08CWpAFgwoQ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IY2JIkFcDAliSpAAa2JEkFMLAlSSqAgS1JUgEMbEmSCvD/ASZrOcjyygh5AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr, bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配，但还是大值这边的尾巴更长"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAepklEQVR4nO3deXhU9dn/8fedkJAg0SAiyg4WFxAIGDZBH0REoKCItKVGfg8ghNKigl4VFa8HgVpF0ILoIxWppRZcKpvKLi1bIZpgwqIQlGIqiw+LEFkCIcz9+2MmNEKWSTJnzszkfl3XXJmZTM73I4Tbc77ne+4jqooxxjghyu0AxpjIZQXGGOMYKzDGGMdYgTHGOMYKjDHGMdXcDlAeV111lTZp0sTtGMaYi2zZsuWIqta5+P2wKjBNmjQhIyPD7RjGmIuISE5x79shkjHGMVZgjDGOsQJjjHGMawVGROJE5DMR2SoiX4jIRLeyGGOc4eYk71mgu6qeFJEYYKOILFfVNBczGWMCyLU9GPU66XsZ43vYlZfGuOzYsWM8/vjjnDp1qtLb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mhC+eBCx8feriDxbZbnETh/6OZ4LI5mBMhfkmXo+JSHMRiQLuK/LtT4DfFL4QkaQSNtNTRBJFpAbeznb/LGPYT4BBhYdGRQ6R/B3PBJEVGFNZ4/Ae0qzB2+ul0G+ALr7J2C+BESX8/Ea8/XoygXdUNau0wVR1G/AisN7XcW1qOcczQWSnqY1rRGQ4cLOqjnE7i3GG7cEYYxxjezDGGMfYHowxxjFWYIwxjrECY4xxjBUYY4xjrMAYYxzz/wF/M5G40BZVigAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果不好"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.6961684813070053\n",
      "The r2 score of RidgeCV on train is 0.7548524440445554\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#1. 设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#2. 生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#3. 模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#4. 预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEGCAYAAABy53LJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de5xVdb3/8dcbEPCKiXjhomBginedMC+Vlyy1FFNMrLwUpdWhczqdOunpmKadX3mym2EahmXWyVtZ4y1LgRQyYhAVh4sMCDJcZBBELnL//P5Ya8t2MzPsDbNm75l5Px+P/Zi1vuu71vqszTCf/Vlr7fVVRGBmZlasTuUOwMzM2hYnDjMzK4kTh5mZlcSJw8zMSuLEYWZmJelS7gBaw7777hv9+/cvdxhmZm3KlClTlkVEr8L2DpE4+vfvT01NTbnDMDNrUyTNb6zdp6rMzKwkThxmZlYSJw4zMyuJE4eZmZUk08Qh6WxJsyTVSbqmkeXdJN2XLp8kqX/afpakKZKmpT/PyFvn0rT9RUl/lrRvlsdgZmbvlF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3A69J+hvw3rT9gYjYAiyRNC5vnQOBhrz5T6SPuu+SLhtM8piIfFuA+9Lp3wD5D6zLTU8hSVYAuwCjJB0LbAYOzeu/lOTRL2YtyonDrDhNDarU3GBLb5E8gwpJA4CvAe+NiBWSfpVbth35zwRan/7czNb/u/9O8oywY0jOIKzL6989jcGsRflUlVlxngYukdQ5ve7wAZKHEU4gGeiok6T9SYYPzZkBDEyn9wLWACvTfuc0sZ9OJE/HBfhkuv3m9AAWpxXPZSTDweYcSmU8HdnaGVccZsV5iOT6xQskVcB/RsQSSb8HziT5A/0yychrK9N1HiVJJE9GxAuSppI8PXUuMLGJ/awBjpA0Jd3OJduJ62fA7yVdTPL02jV5y05PYzBrUX46rtlOkrRHJKO+9SSpQk5Jk8quJH/MT0mvjRSzrdURsUcLxfU0MDQiVrTE9sxyXHGY7bxHJO0NdAVuioglABHxlqTrScZ2frU1A0pPp/3QScOy4IrDzMxK4ovjZmZWEicOMzMriROHmZmVxInDzMxK4sRhZmYl+f/AKs/80wzOiQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.1\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>RM</td>\n",
       "      <td>0.452377</td>\n",
       "      <td>0.449104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ZN</td>\n",
       "      <td>0.129239</td>\n",
       "      <td>0.125966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.103221</td>\n",
       "      <td>0.099911</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>B</td>\n",
       "      <td>0.078899</td>\n",
       "      <td>0.079327</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.059660</td>\n",
       "      <td>0.060075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.037664</td>\n",
       "      <td>0.036712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030071</td>\n",
       "      <td>0.030423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.027465</td>\n",
       "      <td>0.028356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.013818</td>\n",
       "      <td>0.011491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>AGE</td>\n",
       "      <td>-0.001228</td>\n",
       "      <td>-0.001077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008698</td>\n",
       "      <td>-0.008646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011517</td>\n",
       "      <td>-0.011183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040970</td>\n",
       "      <td>-0.039042</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.055736</td>\n",
       "      <td>-0.055449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.081501</td>\n",
       "      <td>-0.081083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.113548</td>\n",
       "      <td>-0.110192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.151553</td>\n",
       "      <td>-0.145910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.187898</td>\n",
       "      <td>-0.187369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.221874</td>\n",
       "      <td>-0.212619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.386249</td>\n",
       "      <td>-0.374867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.476675</td>\n",
       "      <td>-0.474603</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns   coef_lr  coef_ridge\n",
       "5        RM  0.452377    0.449104\n",
       "1        ZN  0.129239    0.125966\n",
       "20   RAD_24  0.103221    0.099911\n",
       "10        B  0.078899    0.079327\n",
       "3      CHAS  0.059660    0.060075\n",
       "18    RAD_7  0.037664    0.036712\n",
       "19    RAD_8  0.030071    0.030423\n",
       "14    RAD_3  0.027465    0.028356\n",
       "2     INDUS  0.013818    0.011491\n",
       "6       AGE -0.001228   -0.001077\n",
       "15    RAD_4 -0.008698   -0.008646\n",
       "16    RAD_5 -0.011517   -0.011183\n",
       "13    RAD_2 -0.040970   -0.039042\n",
       "17    RAD_6 -0.055736   -0.055449\n",
       "12    RAD_1 -0.081501   -0.081083\n",
       "8       TAX -0.113548   -0.110192\n",
       "4       NOX -0.151553   -0.145910\n",
       "9   PTRATIO -0.187898   -0.187369\n",
       "0      CRIM -0.221874   -0.212619\n",
       "7       DIS -0.386249   -0.374867\n",
       "11    LSTAT -0.476675   -0.474603"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.6945099371682092\n",
      "The r2 score of LassoCV on train is 0.7548861511225583\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python\\lib\\site-packages\\sklearn\\model_selection\\_split.py:1978: FutureWarning: The default value of cv will change from 3 to 5 in version 0.22. Specify it explicitly to silence this warning.\n",
      "  warnings.warn(CV_WARNING, FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#2. 生成学习器实例\n",
    "#lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "#1. 设置超参数搜索范围\n",
    "#Lasso可以自动确定最大的alpha，所以另一种设置alpha的方式是设置最小的alpha值（eps） 和 超参数的数目（n_alphas），\n",
    "#然后LassoCV对最小值和最大值之间在log域上均匀取值n_alphas个\n",
    "# np.logspace(np.log10(alpha_max * eps), np.log10(alpha_max),num=n_alphas)[::-1]\n",
    "\n",
    "#2 生成LassoCV实例（默认超参数搜索范围）\n",
    "lasso = LassoCV()  \n",
    "\n",
    "#3. 训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#4. 测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
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c6noeWOXhZ5aLjBvtcYicul+YWTGQA/ydBw/KcvduM/sS4WdSvzmRBQWH076m0JB40B6HiIjERCfHRUQkJgoOERGJiYJDRERiouAQEZGYKDhERCQm/wOERhRDlPbtRQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 3.0853701706804334e-05\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.502616</td>\n",
       "      <td>0.505543</td>\n",
       "      <td>0.452289</td>\n",
       "      <td>RAD_24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.300666</td>\n",
       "      <td>0.297984</td>\n",
       "      <td>0.301090</td>\n",
       "      <td>RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.202829</td>\n",
       "      <td>0.184468</td>\n",
       "      <td>0.171709</td>\n",
       "      <td>RAD_7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.141833</td>\n",
       "      <td>0.147403</td>\n",
       "      <td>0.143205</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.172528</td>\n",
       "      <td>0.147279</td>\n",
       "      <td>0.140265</td>\n",
       "      <td>RAD_8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.174058</td>\n",
       "      <td>0.134516</td>\n",
       "      <td>0.140135</td>\n",
       "      <td>RAD_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.087695</td>\n",
       "      <td>0.088869</td>\n",
       "      <td>0.088272</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.075667</td>\n",
       "      <td>0.074143</td>\n",
       "      <td>0.075931</td>\n",
       "      <td>CHAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.007140</td>\n",
       "      <td>0.017002</td>\n",
       "      <td>0.010758</td>\n",
       "      <td>INDUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-0.001587</td>\n",
       "      <td>-0.001742</td>\n",
       "      <td>-0.004042</td>\n",
       "      <td>AGE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.042599</td>\n",
       "      <td>-0.042286</td>\n",
       "      <td>RAD_4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.009046</td>\n",
       "      <td>-0.056407</td>\n",
       "      <td>-0.053816</td>\n",
       "      <td>RAD_5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.101801</td>\n",
       "      <td>-0.104955</td>\n",
       "      <td>-0.101851</td>\n",
       "      <td>CRIM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.170409</td>\n",
       "      <td>-0.176803</td>\n",
       "      <td>-0.170743</td>\n",
       "      <td>NOX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>-0.158660</td>\n",
       "      <td>-0.178692</td>\n",
       "      <td>-0.157054</td>\n",
       "      <td>TAX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>-0.128783</td>\n",
       "      <td>-0.200660</td>\n",
       "      <td>-0.177225</td>\n",
       "      <td>RAD_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.205211</td>\n",
       "      <td>-0.209666</td>\n",
       "      <td>-0.205903</td>\n",
       "      <td>PTRATIO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>-0.221099</td>\n",
       "      <td>-0.272976</td>\n",
       "      <td>-0.264839</td>\n",
       "      <td>RAD_6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.355223</td>\n",
       "      <td>-0.361874</td>\n",
       "      <td>-0.357240</td>\n",
       "      <td>DIS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>-0.331377</td>\n",
       "      <td>-0.399165</td>\n",
       "      <td>-0.366233</td>\n",
       "      <td>RAD_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>-0.459030</td>\n",
       "      <td>-0.459577</td>\n",
       "      <td>-0.457144</td>\n",
       "      <td>LSTAT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    coef_lasso   coef_lr  coef_ridge  columns\n",
       "20    0.502616  0.505543    0.452289   RAD_24\n",
       "5     0.300666  0.297984    0.301090       RM\n",
       "18    0.202829  0.184468    0.171709    RAD_7\n",
       "1     0.141833  0.147403    0.143205       ZN\n",
       "19    0.172528  0.147279    0.140265    RAD_8\n",
       "14    0.174058  0.134516    0.140135    RAD_3\n",
       "10    0.087695  0.088869    0.088272        B\n",
       "3     0.075667  0.074143    0.075931     CHAS\n",
       "2     0.007140  0.017002    0.010758    INDUS\n",
       "6    -0.001587 -0.001742   -0.004042      AGE\n",
       "15    0.000000 -0.042599   -0.042286    RAD_4\n",
       "16   -0.009046 -0.056407   -0.053816    RAD_5\n",
       "0    -0.101801 -0.104955   -0.101851     CRIM\n",
       "4    -0.170409 -0.176803   -0.170743      NOX\n",
       "8    -0.158660 -0.178692   -0.157054      TAX\n",
       "13   -0.128783 -0.200660   -0.177225    RAD_2\n",
       "9    -0.205211 -0.209666   -0.205903  PTRATIO\n",
       "17   -0.221099 -0.272976   -0.264839    RAD_6\n",
       "7    -0.355223 -0.361874   -0.357240      DIS\n",
       "12   -0.331377 -0.399165   -0.366233    RAD_1\n",
       "11   -0.459030 -0.459577   -0.457144    LSTAT"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
